﻿using System.Reflection;
using ApiLib.RCL.Components.AutoTable.Attributes;
using ApiLib.RCL.Models;
using BootstrapBlazor.Components;
using Microsoft.AspNetCore.Components.Forms;

namespace ApiLib.RCL.Components.AutoTable.Models;

/// <summary>
/// 自动表单实体对象
/// </summary>
public abstract class IAutoTable<T>// : DynamicObject 
    where T : IAutoTable<T>
{
    /// <summary>
    /// 主机地址
    /// </summary>
    /// <returns></returns>
    public abstract string GetHost();
    /// <summary>
    /// 主键
    /// </summary>
    public virtual int Id { get; set; }

    // public abstract string Host { get; }
    /// <summary>
    /// 查询
    /// </summary>
    /// <param name="form"></param>
    /// <returns></returns>
    public abstract Task<BaseResponse<ListResponse<T>>?> OnQuery(Dictionary<string, object> form);

    /// <summary>
    /// 添加编辑
    /// </summary>
    /// <returns></returns>
    public virtual Task<BaseResponse<bool>?> OnSaveOrUpdate()
    {
        throw new NotImplementedException("OnSaveOrUpdate：未实现");
    }

    /// <summary>
    /// 删除
    /// </summary>
    /// <returns></returns>
    public virtual Task<BaseResponse<bool>?> OnDelete()
    {
        throw new NotImplementedException("OnDelete：未实现");
    }

    /// <summary>
    /// 导出
    /// </summary>
    /// <returns></returns>
    public virtual Task<Stream?> OnExport(Dictionary<string, object> form)
    {
        throw new NotImplementedException("OnExport：未实现");
    }
    
    /// <summary>
    /// 导出模板
    /// </summary>
    /// <returns></returns>
    public virtual Task<Stream?> OnExportTemplate()
    {
        throw new NotImplementedException("OnExportTemplate：未实现");
    }

    /// <summary>
    /// 上传附件
    /// </summary>
    public virtual Task<BaseResponse<string>?> OnUpload(IBrowserFile file)
    {
        throw new NotImplementedException("OnUpload：未实现");
    }
    
    /// <summary>
    /// 上传附件
    /// </summary>
    public virtual Task<BaseResponse<string>?> OnUpload(Stream stream,string fileName)
    {
        throw new NotImplementedException("OnUpload：未实现");
    }
    
    /// <summary>
    /// 上传
    /// </summary>
    public virtual Task<BaseResponse<bool>?> OnImport(IBrowserFile file)
    {
        throw new NotImplementedException("OnImport：未实现");
    }
    
    /// <summary>
    /// 获取选择项
    /// </summary>
    /// <returns></returns>
    public virtual Task<List<SelectedItem>?> GetSelectedItems(string key)
    {
        throw new NotImplementedException("GetSelectedItems：未实现");
    }

    /// <summary>
    /// 获取TableAttribute
    /// </summary>
    /// <returns></returns>
    public TableAttribute? GetTableAttribute()
    {
        return GetType().GetCustomAttribute<TableAttribute>();
    }
}